package com.csthink.common.infrastructure.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * All error code and it's detail description
 *
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-09
 */
@Getter
@AllArgsConstructor
public enum ErrorEnum {

    UNKNOWN_ERROR(-1),
    INVALID_PARAMETER(100),

    /**
     * 4xx
     */
    BAD_REQUEST(400),
    UNAUTHORIZED(401),
    FORBIDDEN(403),
    NOT_FOUND(404),
    NOT_ACCEPTABLE(406),

    /**
     * 5xx
     */
    INTERNAL_SERVER_ERROR(500),

    /**
     * validation error
     */
    INVALID_INPUT(10001),
    INVALID_GREATER_THAN_LIMIT(10002),
    INVALID_ORDER_RULE(10003),
    EMPTY_FILE(10004),
    INSECURE_FILE(10005),
    FILE_NOT_ACCESS(10006),
    FILE_SIZE_EXCEED_MAX_LIMIT(10007),
    DELETE_FILE_FAILED(10008),
    NOT_VALID_FILE_TYPE(10009),
    CSV_EXCEEDED_LIMIT(10010),
    EMAIL_INVALID(10011),


    /**
     * user error code
     */
    USER_NOT_FOUND(11001),
    USER_NOT_LOGIN(11002),

    /**
     * role error
     */
    ROLE_NOT_FOUND(12001),

    /**
     * permission \ rolePermission error
     */
    PERMISSION_NOT_FOUND(13001),

    /**
     * Authentication
     */

    /**
     * account error code
     */
    ACCOUNT_EXIST(20001),
    ACCOUNT_USER_NOT_EXIST(20002),
    ACCOUNT_NOT_FOUND(20003),

    /**
     * CORS Config error
     */
    CORS_CONFIG_NOT_FOUND(21001),
    CORS_CONFIG_DOMAINS_EXCEED_MAX_LIMIT(21002),
    CORS_MEETING_WEB_DOMAIN_NOT_VERIFIED(21003),
    CORS_SUB_DOMAIN_FORMAT_INVALID(21004),
    CORS_WHITE_LIST_CHECK_FAILED(21005),

    /**
     * limiter error
     */
    SERVER_BUSY(30001),
    LIMITER_KEY_INVALID(30002),

    /**
     * Jwt error
     */
    JWT_TOKEN_INVALID(40001),
    JWT_TOKEN_EXPIRED(40002),
    JWT_TOKEN_ISSUER_AUDIENCE_NOT_MATCH(40003),

    /**
     * request third party error
     */
    REQUEST_THIRD_PARTY_FAILED(50001),

    /**
     * op user error
     */
    OP_USER_NOT_FOUND(40001),
    OP_USER_EXIST(40004),

    /**
     * Op System Config Error
     */
    OP_SYSTEM_CONFIG_KEY_NOT_EXIST(230000),

    /**
     * Audit log error
     */


    /**
     * file
     */
    FILE_IN_VALID_FILE_ID(450001),

    /**
     * Global variables
     */
    GLOBAL_VARIABLE_INVALID_DATA_TYPE(460001),
    GLOBAL_VARIABLE_INVALID_DATA_FORMAT(460002),
    GLOBAL_VARIABLE_INVALID_GROUP_TYPE(460003),
    GLOBAL_VARIABLE_GROUP_NOT_EXIST(460005),
    GLOBAL_VARIABLE_NOT_EXIST(460006),
    GLOBAL_VARIABLE_EXIST(460007),
    GLOBAL_VARIABLE_GROUP_EXIST(460008),
    GLOBAL_VARIABLE_MAX_SIZE_EXCEED(460010),
    GLOBAL_VARIABLE_GROUP_MAX_SIZE_EXCEED(460011),
    GLOBAL_VARIABLE_INVALID_ENTITY_CATEGORY(460012),

    FILE_TYPE_NOT_SUPPORTED(46013),
    FILE_NAME_IS_NULL(46014),
    FILE_NOT_EXIST(470003);

    private final int errorCode;

    @Override
    public String toString() {
        return String.format("%s[%d]", this.name(), this.errorCode);
    }

}
